# -*- coding: utf-8 -*-
# Python 计算数组元素之和

# 定义一个数字列表，并计算列表元素之和。

# demo-1
total = 0
list1 = [11, 5, 17, 18, 23]

for ele in range(0, len(list1)):
    total += list1[ele]

print('列表元素之和：', total)

# demo-2
total = 0
ele = 0

list1 = [11, 5, 17, 18, 23]

while(ele < len(list1)):
    total += list1[ele]
    ele += 1

print('列表元素之和：', total)

# demo-3
list1 = [11, 5, 17, 18, 23]

def sumOfList(list, size):
    if(size == 0):
        return 0
    else:
        return list[size - 1] + sumOfList(list, size - 1)

total = sumOfList(list1, len(list1))
print('列表元素之和：', total)